package com.clothing.controller.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.clothing.bean.ArticleTypeJson;
import com.clothing.controller.BaseController;
import com.clothing.entity.AppVersion;
import com.clothing.entity.ArticleType;
import com.clothing.service.AppVersionService;
import com.clothing.service.ArticleTypeService;
import com.clothing.utils.AjaxMsg;
import com.clothing.utils.Utils;

/**
 * @ClassName: ArticleTypeController 
 * @Description: TODO(文章类别) 
 * @author Charles.Tao 
 * @date 2017年9月7日 上午9:38:03 
 * @version 1.0
 */
@RequestMapping("/app/articleType")
@Controller("appArticleTypeController")
public class ArticleTypeController extends BaseController
{
    @Autowired
    private ArticleTypeService articleTypeService;
    
    @Autowired
    private AppVersionService appVersionService;
    
    /**
     * @Title: list 
     * @Description: TODO(获取文章类型列表) 
     * @param @return 设定文件 
     * @return String 返回类型 
     * @throws
     */
    @RequestMapping(value = "/getList.json", method = RequestMethod.GET)
    @ResponseBody
    public String list()
    {
        AppVersion appVersion = appVersionService.find(1L);
        List<ArticleType> articleTypes = null;
        JSONArray ja = null;
        
        if (appVersion.getIsBeta())
        {
            articleTypes = articleTypeService.findShowList();
            
        }
        else
        {
            articleTypes = articleTypeService.findList(6L);
        }
        
        if (!Utils.isEmpty(articleTypes))
        {
            ja = new JSONArray();
            
            for (ArticleType articleType : articleTypes)
            {
                ArticleTypeJson json = new ArticleTypeJson();
                json.setId(articleType.getId());
                json.setName(articleType.getName());
                json.setIcon(articleType.getFullIcon());
                ja.add(json);
            }
        }
        
        return new AjaxMsg(true, ja).toString();
    }
}
